﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Data.SqlClient;
using System.Collections;


namespace homework11
{
    public partial class Form1 : Form
    {
        ArrayList enWords = new ArrayList();
        ArrayList chWords = new ArrayList();
        List<Word> words = new List<Word>();
        int id = 0;
        public Form1()
        {
            InitializeComponent();
            string sqliteString = @"Data Source=D:\unity\wordDB.db";
            SQLiteConnection connection = new SQLiteConnection(sqliteString);
            string sql = "SELECT ch,en FROM word";
            connection.Open();
            SQLiteCommand cmd = new SQLiteCommand(sql, connection);
            SQLiteDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                enWords.Add(dr["en"]);
                chWords.Add(dr["ch"]);
            }

            for (int i = 0; i < enWords.Count; i++)
            {
                words.Add(new Word
                {
                    en = enWords[i].ToString(),
                    ch = chWords[i].ToString()
                });
            }
           chtextBox.Text = words[id].ch;


           
        }
       
        public void check()
        {
            if (entextBox.Text == words[id].en)
            {
                resulttextBox.Text = "太棒了，答对了！！";
                
            }
            else
                resulttextBox.Text = "答错了！要加油哦";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            check();
        }

        private void nexTbutton_Click(object sender, EventArgs e)
        {
            if (id++ <= words.Count)
            {
                resulttextBox.Text = string.Empty;
                entextBox.Text = String.Empty;
                chtextBox.Text = words[id].ch;
            }
            else
                resulttextBox.Text = "已全部检测完毕！";
        }
    }
    public class Word
    {
        public string en { get; set; }

        public string ch { get; set; }
    }
}
